<%--
  Created by IntelliJ IDEA.
  User: dengdc
  Date: 2017/7/19
  Time: 17:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="s" uri="http://www.springframework.org/tags" %>
<html>
<head>
    <title>diyishou </title>
    <jsp:include page="../../head.jsp"/>
    <script type="text/javascript">
        //
        <!--业务编码、集装箱号、合同协议号、提运单号、进出口类型、收发货人、供应商、下单人-->
        var formSetting = {
            title: "查询信息",
            module: 'query',
            columns: [
                {
                    name: "status",
                    label: "状态",
                    type: "dropdown",
                    data: [["草稿", "0"], ["生效", "1"]]
                }, {
                    name: "bizSceneId",
                    label: "业务场景",
                    type: "dropdown",
                    data: [["进口一般贸易", "IMN"], ["出口一般贸易", "EXN"], ["进口加工贸易", "IMP"],
                           ["出口加工贸易", "EXP"]]
                }],
            buttons: {
                custom: [{
                             id: "updatebtn0",
                             value: "新增",
                             click: function () {
                                 //todo
                                 /*alert("新增");*/
                                 window.location.href = '/views/yxtPc/pages/rule.html?operate=add';
                             }
                         },
                         {
                             id: "updatebtn1",
                             value: "修改",
                             click: function () {
                                 //todo
                                 var id = $("#originalDeclarationGrid").jqGrid("getGridParam",
                                                                               "selrow");
                                 if (id) {
                                     /*alert("主键" + id);*/
                                     window.location.href = '/views/yxtPc/pages/rule.html?operate=modify&pruleId='+id;
                                 } else {
                                     jw.alert("请点击需要操作的数据!");
                                 }
                             }
                         },
                         {
                             id: "updatebtn2",
                             value: "查看",
                             click: function () {
                                 //todo
                                 var id = $("#originalDeclarationGrid").jqGrid("getGridParam",
                                                                               "selrow");
                                 //获取单条数据
                                 var rowData = $("#originalDeclarationGrid").jqGrid("getRowData",
                                                                                    id);

                                 if (id) {
                                     /*alert("主键" + id);*/
                                     window.location.href = '/views/yxtPc/pages/rule.html?operate=view&pruleId='+id;
                                 } else {
                                     jw.alert("请点击需要操作的数据!");
                                 }
                             }
                         },
                         {
                             id: "updatebtn2",
                             value: "删除",
                             click: function () {
                                 var ids = getSels("originalDeclarationGrid");
                                 if (ids == null) {
                                     return;
                                 }

                                 $.ajax({
                                            type: "POST",
                                            url: "/policyRules/delete",
                                            contentType: "application/json",
                                            data: JSON.stringify(ids),
                                            success: function (r) {
                                                if (r.error_code == 0) {
                                                    jw.alert("删除成功");
                                                    $("#originalDeclarationGrid").trigger("reloadGrid");
                                                } else {
                                                    alert(r.msg);
                                                }
                                            }
                                        });
                             }
                         }]
            },
            grid: {
                id: "originalDeclarationGrid",
                title: "查询结果",
                url: "/policyRules/list",
                colModel: [{
                               index: "id",
                               name: "id",
                               key: true
                           },
                           {
                               label: '状态', name: 'status', index: 'status',
                               formatter: function (value, options, row) {
                                   if (value == "0") {//0 草稿， 1 生效， -1 无效
                                       return "草稿";
                                   } else if (value == "1") {
                                       return " 生效";
                                   }
                               }
                           },
                           {label: '提醒内容', name: 'noticeMsg', index: 'notice_msg'},
                           {label: '说明', name: 'decript', index: 'decript'},
                           {label: '修改时间', name: 'modifyTime', index: 'modify_time'},
                           {label: '修改人', name: 'modifier', index: 'modifier'},
                           {label: '创建时间', name: 'createTime', index: 'create_time'},
                           {label: '创建人', name: 'creator', index: 'creator'}],
                multiselect: true
            }
        };
        $(document).ready(function () {
            $("#table").mrdForm(formSetting);
            doResize();
            $(window).resize(function () {
                doResize();
            });

            $(".ui-jqgrid-title").text("政策列表");
        });

        function doResize() {
            var ss = getPageSize();
            $("#originalDeclarationGrid").jqGrid('setGridHeight', ss.WinH - 240);
        }

        function getPageSize() {
            var winW, winH;
            if (window.innerHeight) {// all except IE
                winW = window.innerWidth;
                winH = window.innerHeight;
            } else if (document.documentElement && document.documentElement.clientHeight) {// IE 6 Strict Mode
                winW = document.documentElement.clientWidth;
                winH = document.documentElement.clientHeight;
            } else if (document.body) { // other
                winW = document.body.clientWidth;
                winH = document.body.clientHeight;
            }
            return {WinW: winW, WinH: winH};
        }

        //选择多条记录
        function getSels(gridId) {
            var grid = $("#" + gridId);
            var rowKey = grid.getGridParam("selrow");
            if (!rowKey) {
                alert("请选择一条记录");
                return;
            }

            return grid.getGridParam("selarrrow");
        }
    </script>
</head>
<body>
<div id="table"></div>
</body>
</html>
